package com.example.sourcecodelearning.modules.product.impl;

import cn.hutool.core.util.RandomUtil;
import com.example.sourcecodelearning.modules.product.entity.ProductEntity;
import com.example.sourcecodelearning.util.ManticoreSearchUtils;
import com.manticoresearch.client.model.SuccessResponse;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductService {

    @Resource
    private ManticoreSearchUtils manticoreSearchUtils;

    public SuccessResponse saveProduct() {
        String index = "products";
        ProductEntity productEntity = ProductEntity.builder()
                .title(RandomUtil.randomString(12))
                .price(RandomUtil.randomDouble(1, 10000))
                .build();
        return manticoreSearchUtils.insert(index, productEntity);
    }

    public List<Object> getProductList() {
        return manticoreSearchUtils.select("select * from products");
    }

}
